﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using System.Text;

namespace HY.WEB.SA
{
    public partial class comp_view_job : PageBase
    {
        public string us,bh, whe = "", path = "";           
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
             bh = Session["bh"].ToString();


            if (!IsPostBack)
            {

                if (!String.IsNullOrEmpty(Request["sid"]))
                {
                     hidsid.Text = Request["sid"].Trim();                
                }

                if (!String.IsNullOrEmpty(Request["cbh"]))
                {
                    hidsbh.Text = Request["cbh"].Trim();
                    hidsid.Text = BLL.Bllbase.get_val("company", "sid", "cbh='" + hidsbh.Text + "'");
                }
                btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
                dtteldel.OnClientClick = Grid2.GetNoSelectionAlertReference("至少选择一项！");
                btaddjob.OnClientClick = Window1.GetShowReference("../sales/jobs_add.aspx?cbh=" + hidsbh.Text + "", "添加职位");
                btaddtel.OnClientClick = Window1.GetShowReference("../sales/tel_add.aspx?cbh=" + hidsbh.Text + "", "添加职位");
      
                fill2();
                fill_grid();

            }

            if (BLL.Bllbase.chk_comp_fav(hidsbh.Text, bh))
            {
                Panel2.Visible =false;
                //lbltel.Visible = false;
                //lblfax.Visible = false;
                //lblmail.Visible = false;
                //lblqq.Visible = false;
                //lblmsn.Visible = false;
                //lblwebsite.Visible = false;
                //lblsex.Visible = false;
                //lblperson.Visible = false;
                //lbljob.Visible = false;
                //lblmtel.Visible = false;
            }
            else
            {
                Panel2.Visible = true;
                //lbltel.Visible =true;
                //lblfax.Visible = true;
                //lblmail.Visible = true;
                //lblqq.Visible = true;
                //lblmsn.Visible = true;
                //lblwebsite.Visible = true;
                //lblsex.Visible = true;
                //lblperson.Visible = true;
                //lbljob.Visible = true;
                //lblmtel.Visible = true;            
            }
        
        }

        void  fill_grid()
        {
           //职位表
            DataTable table = BLL.Bllbase.get_table("comp_job", "cbh='" + hidsbh.Text + "'");
            Grid1.DataSource = table;
            Grid1.DataBind();

           //电话记录表
            DataTable table2 = BLL.Bllbase.get_table("comp_tel", "cbh='" + hidsbh.Text + "'");
            Grid2.DataSource = table2;
            Grid2.DataBind();

        }

        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
         Grid1.PageIndex = e.NewPageIndex;
        }




       protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
       {
           DataTable table = BLL.Bllbase.get_table("comp_job", "cbh='" + hidsbh.Text + "'");

           DataView view1 = table.DefaultView;
           view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);

           Grid1.DataSource = view1;
           Grid1.DataBind();
       }


        //电话记录翻页
        protected void Grid2_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid2.PageIndex = e.NewPageIndex;
        }
        
        //电话记录排序
        protected void Grid2_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = BLL.Bllbase.get_table("comp_tel", "cbh='" + hidsbh.Text + "'");

            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);

            Grid2.DataSource = view1;
            Grid2.DataBind();
        }
        

        void fill2()
        {
          BLL.CO.company S = new BLL.CO.company();
         
          DataTable d=  S.GetList("sid="+hidsid.Text).Tables[0];

          hidsbh.Text = d.Rows[0]["cbh"].ToString().Trim();
          lblbh.Text = hidsbh.Text;

          lblnm.Text = d.Rows[0]["cname"].ToString().Trim();
          lbldate.Text = d.Rows[0]["updtime"].ToString().Trim();
          lblxz.Text = d.Rows[0]["cntype"].ToString().Trim();
          lblgm.Text = d.Rows[0]["compnum"].ToString().Trim();

          lbladdress.Text = d.Rows[0]["addresss"].ToString();

          lblpost.Text = d.Rows[0]["post"].ToString().Trim();

          lblcity.Text = BLL.Bllbase.get_val("pub_area","svalue","scode='"+d.Rows[0]["city"].ToString()+"'");



          lblfax.Text = d.Rows[0]["cfax"].ToString();



         

          lblwebsite.Text = d.Rows[0]["website"].ToString().Trim();

          lblmail.Text = d.Rows[0]["email"].ToString().Trim();
  


          lblnum.Text = d.Rows[0]["cnum"].ToString().Trim();

          lblht.Text = d.Rows[0]["ht"].ToString().Trim();
            
          lbltype.Text = d.Rows[0]["salestype"].ToString().Trim();

  
           lblstatus.Text = d.Rows[0]["cstatus"].ToString().Trim();

          lblhy.Text = d.Rows[0]["hytype"].ToString().Trim();
          lblmemo.Text =Server.HtmlDecode(d.Rows[0]["memo"].ToString().Trim());

          lblsales.Text = d.Rows[0]["sales"].ToString().Trim();
          lbldtime.Text = d.Rows[0]["updtime"].ToString().Trim();


          lblperson1.Text = d.Rows[0]["person"].ToString().Trim();
          lblsex1.Text = d.Rows[0]["sex"].ToString().Trim();
          lbljob1.Text = d.Rows[0]["job"].ToString().Trim();
          lbltel1.Text = d.Rows[0]["ctel"].ToString();
          lblqq1.Text = d.Rows[0]["qq"].ToString().Trim();
         // lblmsn1.Text = d.Rows[0]["msn"].ToString().Trim();
          lblmtel1.Text = d.Rows[0]["mtel"].ToString().Trim();

          if (form1.Visible)
          {
              DataTable dttel = BLL.Bllbase.get_table("pub_tel", "bh='" + hidsbh.Text + "'");
              int i = 0;


              if (i < dttel.Rows.Count)
              {
                  lblperson2.Text = dttel.Rows[i]["person"].ToString();
                  lblsex2.Text = dttel.Rows[i]["sex"].ToString();
                  lbljob2.Text = dttel.Rows[i]["job"].ToString();
                  lbltel2.Text = dttel.Rows[i]["ctel"].ToString();
                  lblqq2.Text = dttel.Rows[i]["qq"].ToString();
                 // lblmsn2.Text = dttel.Rows[i]["msn"].ToString();
                  lblmtel2.Text = dttel.Rows[i]["mtel"].ToString();
              }

              i = i + 1;
              if (i < dttel.Rows.Count)
              {
                  lblperson3.Text = dttel.Rows[i]["person"].ToString();
                  lblsex3.Text = dttel.Rows[i]["sex"].ToString();
                  lbljob3.Text = dttel.Rows[i]["job"].ToString();
                  lbltel3.Text = dttel.Rows[i]["ctel"].ToString();
                  lblqq3.Text = dttel.Rows[i]["qq"].ToString();
                 // lblmsn3.Text = dttel.Rows[i]["msn"].ToString();
                  lblmtel3.Text = dttel.Rows[i]["mtel"].ToString();
              }
          }
        }


        //取城市
        public static string getcity(string val)
        {
            DataTable dte = BLL.Bllbase.get_table("[pub_area]");
            if (dte.Rows.Count > 0)
                return dte.Rows[0]["svalue"].ToString();
            else
                return "";

        }

        protected void Window1_Close(object sender, EventArgs e)
        {
            // Alert.ShowInTop("弹出窗口关闭了！");
            //string key = txt.Text.Trim();
            //stype = hidstype.Text;
            //try
            //{
            //    if (key == "" & stype != "")
            //        whe = whe + " and " + BLL.pub.pubwhere.get_where_sql(us, tab);

            //    BindGrid();


            //}
            //catch (Exception ex)
            //{
            //    // Alert.Show("查询条件错误");
            //    whe = " cbh in (select cbh from company_fav where sbh='" + bh + "')";
            //}
            //finally
            //{
            //    whe = " cbh in (select cbh from company_fav where sbh='" + bh + "')";
            //}

            //BindGrid();
            fill_grid();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int val = Grid1.PageIndex * Grid1.PageSize;
            StringBuilder sb = new StringBuilder();
            foreach (int row in Grid1.SelectedRowIndexArray)
            {
                sb.Append(Grid1.DataKeys[row + val][0].ToString());
                sb.Append(",");
            }

           // Alert.ShowInTop("你选择了删除项：" + sb.ToString().TrimEnd(','));
            HY.BLL.Bllbase.DeleteList("comp_job", sb.ToString().TrimEnd(','));
            fill_grid();
        }

        protected void btnDelete2_Click(object sender, EventArgs e)
        {
           
            int val = Grid2.PageIndex * Grid2.PageSize;
           
            StringBuilder sb = new StringBuilder();
         
            foreach (int row in Grid2.SelectedRowIndexArray)
            {
                sb.Append(Grid2.DataKeys[row + val][0].ToString());
                sb.Append(",");
            }

           // Alert.ShowInTop("你选择了删除项：" + sb.ToString().TrimEnd(','));
            HY.BLL.Bllbase.DeleteList("comp_tel", sb.ToString().TrimEnd(','));
            fill_grid();

        }

    }
}